package com.mybank.fundtrans.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mybank.fundtrans.entity.Fund;
import com.mybank.fundtrans.service.impl.FundServiceImpl;
import com.mybank.fundtrans.utils.CastRequestToMap;
import com.mybank.fundtrans.utils.PageBean;
import com.alibaba.fastjson.JSON;

public class GetFundController extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
	private FundServiceImpl fundService;
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) {
		fundService=new FundServiceImpl();
		Map map = CastRequestToMap.castRequestToMap(request);
        
        PageBean pageBean=fundService.getFundList(map.get("pages").toString(), map.get("num").toString());
        
        System.out.println(JSON.toJSON(pageBean).toString());
        
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json; charset=utf-8");
        PrintWriter out = null;
        try {
            out = response.getWriter();
            out.write(JSON.toJSON(pageBean).toString());
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (out != null) {
                out.close();
            }
        }


	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		super.doGet(req, resp);
	}
}
